﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.ZNH.ZMCommon;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core;

namespace Baosight.ZNH.ZMCP.UI.PopWindows
{
    public partial class AlarmProject : EFViewCmes
    {
        public AlarmProject()
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
            this.Mode = OperationMode.Insert;
        }

        /// <summary>
        /// 初始化父类EFViewCmesProperty的值，每次点击“确定”、“返回”时执行此方法，从新赋值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.spWindows.GetChildObjects<EFDataField>(null, true);
            base.ViewProperty = _view;
        }


        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommitClick(object sender, RoutedEventArgs e)
        {
            base.OnCommitButtonClick(this.eServiceName, sender, e);
        }

        /// <summary>
        /// 取消按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelClick(object sender, RoutedEventArgs e)
        {
            CmesWindows _window = this.Parent as CmesWindows;
            _window.DialogResult = false;
            _window.Close();
        }

        /// <summary>
        /// 选择工程填入其它字段值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void fdProjectId_ValueChanged(object sender, ValueChangedEventArgs e)
        //{
        //    CmesCustomView custom = (sender as EFDataField).Content as CmesCustomView;
        //    if (custom.ItemObject != null && !"".Equals(custom.ItemObject))
        //    {
        //        this.fdPlanAmount.Value = custom.ItemObject.GetType().GetProperty("fdPlanAmount").GetValue(custom.ItemObject, null);
        //        this.fdAcctualAmount.Value = custom.ItemObject.GetType().GetProperty("fdValidateData").GetValue(custom.ItemObject, null);
        //        this.fdStartDate.Value = custom.ItemObject.GetType().GetProperty("fdBeginDate").GetValue(custom.ItemObject, null);
        //        this.fdLaneId.Value = custom.ItemObject.GetType().GetProperty("fdParentId").GetValue(custom.ItemObject, null);               
                
        //        double plan = 0.0;
        //        if (this.fdPlanAmount.Value != null)
        //        {
        //            Double.TryParse(this.fdPlanAmount.Value.ToString(), out plan);
        //        }
        //        double acctual = 0.0;
        //        if (this.fdAcctualAmount.Value != null)
        //        {
        //            Double.TryParse(this.fdAcctualAmount.Value.ToString(), out acctual);
        //        }

        //        this.fdSurplusAmount.Value = plan - acctual;
        //    }
        //}

        /// <summary>
        /// 选择工程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fdNo_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            try
            {
                EFComboBox select = (sender as EFDataField).Content as EFComboBox;
                this.fdProjectPlace.Value = select.SelectedItem.GetType().GetProperty("fdProjectPlace").GetValue(select.SelectedItem, null);
                this.fdName.Value = select.SelectedItem.GetType().GetProperty("fdName").GetValue(select.SelectedItem, null);
                this.fdLaneId.Value = select.SelectedItem.GetType().GetProperty("fdParentId").GetValue(select.SelectedItem, null);               
                this.fdProjectId.Value = select.SelectedItem.GetType().GetProperty("fdKeyId").GetValue(select.SelectedItem, null);
                this.fdStartDate.Value = select.SelectedItem.GetType().GetProperty("fdBeginDate").GetValue(select.SelectedItem, null);
            }
            catch { }
        }

    }
}
